#!/usr/bin/env python
# coding: utf-8

# In[1]:


#Importing PulP solver
from pulp import *


# In[2]:


#Inputing the Demand points
demand_points=['Port of Newcastle','Port of Hedland','Port of Vienna','Port of Mina','Port of Antwerp','Port of Santos','Port of Montreal','Port of Vancouver','Port of Shanghai','Port of Hamburg_Czeck','Port of Alexandria','Port of Marseille','Port of Hamburg_Germany','Port of Budapest','Port of Jawaharlal Nehru','Port of Tanjung Priok','Port of Bandar Abbas','Port of Umm Qasr','Port of Haifa','Port of Gioia Tauro','Port of Nagoya','Port of Aqaba','Port of Busan','Port of Shuwaikh','Port of Beirut','Port of Manzanillo','Port of Rotterdam','Port of Salalah','Port of Gaza','Port of Gdansk','Port of Doha','Port of King Abdul Aziz','Port of Jeddah','Port of Bratislava','Port of Durban','Port of Algeciras','Port of Gothenburg','Port of Latakia','Port of Kaohsiung','Port of Bangkok','Port of Mersin','Port of Jebel Ali','Port of Immingham','Port of New York','Port of Los Angeles','Port of Hodeidah']


# In[3]:


demand_points


# In[4]:


#Inputing the Supply Points
supply_points=['Port of Shanghai','Port of Marseille','Port of Hamburg_Germany','Port of Budapest','Port of Jawaharlal Nehru','Port of Nagoya','Port of Busan','Port of Manzanillo','Port of Kaohsiung','Port of Mersin','Port of Immingham','Port of New York','Port of Los Angeles']


# In[5]:


supply_points


# In[6]:


#Inputing the distances
distance = dict(zip(supply_points,[dict(zip(demand_points, [5140,3701,10444,6882,11907,13268,11673,4956,0,12277,8365,10048,12277,10330,5293,2909,6557,7139,8336,9335,1007,7912,535,7094,8385,6843,11999,6270,7660,12993,6814,6922,7341,10432,8418,10346,12539,8550,597,2872,8546,6627,12049,10547,5688,6802])),
dict(zip(demand_points, [11599,9088,2980,5332,2339,6204,4871,10996,10048,2708,1805,0,2708,2868,5224,7714,5024,5603,1946,730,10928,2282,10566,5558,1900,8209,2430,4081,1631,3425,5267,5388,2709,2971,7032,778,2971,1830,9485,8270,1806,5080,2481,4293,9700,3245])),
dict(zip(demand_points, [13825,11314,5209,7561,426,7026,3669,11819,12277,0,4034,2708,0,5095,7451,9842,7250,7832,4173,3032,13155,4509,12793,7788,4130,9031,341,6307,3973,870,7493,7615,4935,5197,8433,1929,417,4057,11711,10496,4032,7306,448,4195,10522,5475])),
dict(zip(demand_points, [11879,9368,103,5615,4726,8591,7258,13383,10330,5095,2047,2868,5095,0,5505,7995,5304,5886,2192,2154,11208,2563,10846,5841,2148,10565,4817,4362,1992,5812,5547,5669,2989,102,7312,3165,5360,2052,9766,8550,2028,5360,4868,6728,12056,3528])),
dict(zip(demand_points, [6956,4445,5619,1589,7082,9552,9614,9428,5293,7451,3540,5224,7451,5505,0,3071,1265,1847,3510,4510,6171,3086,5810,1802,3560,12946 ,7173,1143,3243,8167,1522,1630,2515,5607,4714,5521,7715,3725,4727,3513,3720,1335,7224,9036,10104,1977])),
dict(zip(demand_points, [4768,4088,11322,7759,12786,11468,10961,4321,1007,13155,9243,10928,13155,11208,6171,3787,7435,8017,9214,10213,0,8790,612,7972,9263,6131,12877,7148,8308,13871,7692,7800,8219,11310,9308,11224,13418,9428,1498,3750,9424,7505,12927,9835,4992,7680])),
dict(zip(demand_points, [5141,3770,10960,7398,12424,13783,11234,4517,535,12793,8882,10566,12793,10846,5810,3426,7074,7655,8852,9852,612,8428,0,7611,8901,6404,12515,6786,8020,13509,7330,7438,7857,10949,8939,10863,13056,9066,1137,3388,9062,7143,12565,10108,5249,7318])),
dict(zip(demand_points, [6715,8542,10679,13061,8663,7223,5899,2814,6843,9031,9534,8209,9031,10565,12946 ,8920,12745,13332,9673,8533,6131,10011,6404,13286,9631,0,8736,11791,8088,9730,12977,13099,10419,10681,10919,7413,9277,9541,7268,8865,9516,12790,8787,4237,1490,10974])),
dict(zip(demand_points, [4693,3258,9880,6316,11343,12691,13875,5419,597,11711,7800,9485,11711,9766,4727,2343,5991,6573,7770,8771,1498,7346,1137,6528,7819,7268,11434,5704,7144,12430,6248,6356,6775,9868,7930,9782,11978,7986,0,2307,7981,6063,11485,10972,6129,6236])),
dict(zip(demand_points, [10095,7584,2142,3831,3664,7528,6195,12320,8546,4032,546,1806,4032,2028,3720,6210,3520,4102,233,1091,9424,778,9062,4057,191,9516,3755,2577,316,4751,3763,3885,1205,2130,5530,2102,4299,89,7981,6766,0,3576,3804,5617,11024,1744])),
dict(zip(demand_points, [13598,11088,4982,7334,313,6799,3435,11591,12049,448,3806,2481,448,4868,7224,9714,7023,7605,3944,2805,12927,4282,12565,7560,3903,8787,282,6081,3399,1166,7267,7388,4708,4970,8207,1703,714,3830,11485,10269,3804,7080,0,3968,10295,5247])),
dict(zip(demand_points, [9689,12899,6839,9168,3827,6148,1729,7051,10547,4195,5618,4293,4195,6728,9036,11525,8862,9417,5756,4617,9835,6104,10108,9392,5715,4237,3918,7930,5196,4316,9392,9222,6521,6830,9902,3515,3864,5642,10972,12081,5617,8918,3968,0,5734,7105])),
dict(zip(demand_points, [6466,7885,12171,14552,10154,8718,7389,1319,5688,10522,11025,9700,10522,12056,10104,7910,11057,11524,11048,10024,4992,11501,5249,11504,11122,1490,10245,11137,9280,11242,11279,11344,11927,12158,12410,8922,10789,11049,6129,7730,11024,11116,10295,5734,0,12465]))]))


# In[7]:


distance


# In[8]:


#Inputing the Fiber Demand
Fiber_demand=dict(zip(demand_points, [36310.6696,579718.6220,32245.5899,93954.0000,176965.9293,19540.5000,207820.3497,154759.8348,2154713.2850,610716.9348,2457.0000,799890.7822,987772.8956,112444.5000,3033829.6200,457500.1178,8179.5000,546.0000,94.5000,109188.5173,4790234.3290,102753.0000,3473051.2330,170338.2467,1512.0000,165228.0000,54142.8634,10.5000,0.0000,80437.4174,168850.5000,161279.7866,152355.2134,300565.9790,74707.5000,520674.1459,54983.9464,598.5000,279204.3872,1042463.4260,450887.5142,13240.5000,455326.9563,1828466.5530,1791676.4820,105.0000]))


# In[9]:


Fiber_demand


# In[10]:


#Inputing the Fiber Supply
Fiber_supply=dict(zip(supply_points, [7891205.716800,4720787.525080,3013639.269080,1741988.017000,1532949.455000,1498109.694000,1289071.132000,1080032.570000,1010353.050000,870994.008400,627115.686000,256623.912100,178873.092100])) 


# In[11]:


Fiber_supply


# In[12]:


# Set Problem Variables
prob = LpProblem("Transportation", LpMinimize)


# In[13]:


prob


# In[14]:


# Set Problem Variables
routes = [(i,j) for i in supply_points for j in demand_points]


# In[15]:


routes


# In[16]:


# Decision Variables
X = LpVariable.dicts("ShipmentAmount",(supply_points, demand_points),0)


# In[17]:


X


# In[18]:


# Objective Function
prob += sum(X[i][j]*distance[i][j] for (i,j) in routes)


# In[19]:


prob


# In[20]:


# Constraints
for j in demand_points:
    prob += sum(X[i][j] for i in supply_points) >= Fiber_demand[j]
    
prob


# In[21]:


# Constraints
for i in supply_points:
    prob += sum(X[i][j] for j in demand_points) == Fiber_supply[i]
prob


# In[22]:


prob.solve()

print("Status:", LpStatus[prob.status])

for v in prob.variables():
    if v.varValue > 0:
        print(v.name, "=", v.varValue)

print("Total kilogram_miles =", value(prob.objective))


# In[ ]:




